# -*- coding: utf-8 -*-

from pages.basePage import BaseHandler
import jinja2
import os
from models.usuario import Usuario
from models.persona import Persona

jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
        
class PersonaCoisada:
    nome = None
    descricao = None
    pid = None

class EscolherPersona(BaseHandler):
    def get(self):
        userId = self.session.get('userid')        
        user = None
        if userId is not None:
            user = Usuario.get_by_id(userId)
        if user is None:
            self.redirect('/')
            return
        url = self.session.get('url')
        if url is None:
            self.redirect('/')
            return
        
        vinc = self.request.get('vinc')

        personas = Persona.all()
            
        personasCoisadas = []
        for persona in personas:
            personaCoisada = PersonaCoisada()
            personaCoisada.nome = persona.nome
            personaCoisada.descricao = persona.descricao
            personaCoisada.pid = persona.key().id()
            personasCoisadas.append(personaCoisada)
            
        self.session['condicoes'] = {'dict' : 'dict'}
        
        template_values = {
            'vinc' : vinc,
            'user' : user,
            'nome' : "".encode('utf-8'),
            'idade1' : "",
            'idade2' : "",
            'sexo' : "".encode('utf-8'),
            'descricao' : "".encode('utf-8'),
            'personas' : personasCoisadas,
            'url' : url
        }
            
        template = jinja_environment.get_template('html/criarCenarioSelecionarPersona.html')
        self.response.out.write(template.render(template_values))
            